#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
double find(int* nums1, int nums1Size, int* nums2, int nums2Size)
{

    int k = 0;
    int index1 = 0;
    int index2 = 0;
    int flag = 0;
    if ((nums1Size + nums2Size) % 2 == 1)
    {
        flag = 1;
        k = (nums1Size + nums2Size) / 2 + 1;
    }
    else
    {
        k = (nums1Size + nums2Size) / 2;
    }
    while (1)
    {
        if (index1 == nums1Size)
        {
            if (flag == 1)
                return (double)nums2[index2 + k - 1];
            else
                return ((double)nums2[index2 + k - 1] + (double)nums2[index2 + k]) / 2.0;


        }
        else if (index2 == nums2Size)
        {
            if (flag == 1)
                return (double)nums1[index1 + k - 1];
            else
                return ((double)nums1[index2 + k - 1] + (double)nums1[index2 + k]) / 2.0;
        }
        else if (k == 1)
        {
            if (flag == 1)
                return nums2[index2] > nums1[index1] ? (double)nums1[index1] : (double)nums2[index2];
            else
                return ((double)nums1[index1] + (double)nums2[index2]) / 2.0;
        }
        int j = k / 2;
        int newindex1 = nums1Size > j + index1 ? j + index1 - 1 : nums1Size - 1;
        int newindex2 = nums2Size > j + index2 ? j + index2 - 1 : nums2Size - 1;
        if (nums1[newindex1] >= nums2[newindex2])
        {
            k -= (newindex2 - index2 + 1);
            index2 = newindex2 + 1;
        }
        else
        {
            k -= (newindex1 - index1 + 1);
            index1 = newindex1 + 1;
        }
    }


}
int main()
{
    int a[4] = { 1,2,3,4 };
    int b[4] = { 5,6,8,9 };
    double x = find(a, 4, b, 4);
    printf("%lf\n", x);
    return 0;
}